package com.chuangyang.fixboxmaster.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuangyang.fixboxmaster.AppData;
import com.chuangyang.fixboxmaster.R;
import com.chuangyang.fixboxmaster.bean.CashRequest;

import java.util.ArrayList;

/**
 * Created by vanshu on 15/8/6 16:05.
 */
public class CashRepairRequestAdapter  extends BaseAdapter{
    private ArrayList<CashRequest> cashRequestArrayList = new ArrayList<>();


    public CashRepairRequestAdapter(ArrayList<CashRequest> orders){
        this.cashRequestArrayList=orders;
    }


    public CashRepairRequestAdapter(ArrayList<CashRequest> orders,int type){
        this.cashRequestArrayList=orders;
    }

    @Override
    public int getCount() {
        return cashRequestArrayList == null ? 0 : cashRequestArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return cashRequestArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(AppData.getContext()).inflate(R.layout.cash_repair_request_item, parent, false);
            holder = new ViewHolder();
            holder.mCashRequestTitle = (TextView) convertView.findViewById(R.id.tv_cash_request);
            holder.mCashRequestTime = (TextView) convertView.findViewById(R.id.tv_cash_request_time);
            holder.mCashRequestBalance = (TextView) convertView.findViewById(R.id.tv_balance);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(cashRequestArrayList.get(position).title.equals("账户提现")){
            holder.mCashRequestTitle.setText(cashRequestArrayList.get(position).title);
            holder.mCashRequestTime.setText(cashRequestArrayList.get(position).applyDate);
            holder.mCashRequestBalance.setText(cashRequestArrayList.get(position).balanceAmount);
        }else{
            holder.mCashRequestTitle.setText(cashRequestArrayList.get(position).title);
            holder.mCashRequestTime.setText(cashRequestArrayList.get(position).createDate);
            holder.mCashRequestBalance.setText(cashRequestArrayList.get(position).totalPrice);
        }

        return convertView;
    }


    public static class ViewHolder{
        public TextView mCashRequestTitle;
        public TextView mCashRequestTime;
        public TextView mCashRequestBalance;
        public TextView mOrderMoney;
    }

}
